package com.xaicode.locker.JavaSJMS.three.StructureMode.Composite;

import java.util.Enumeration;

/**
 * 树形结构调用
 * @author Locker
 * 	  <br> 2017年5月5日 上午9:28:44
 * @version v1.0
 */
public class Tree {

	TreeNode node = null;
	
	public Tree(){}
	
	public Tree(String name) {
		node = new TreeNode(name);
	}
	
	public static void main(String[] args) {
		Tree tree = new Tree("A");
		TreeNode node2 = new TreeNode("B");
		TreeNode node3 = new TreeNode("C");
		TreeNode node4 = new TreeNode("D");
		TreeNode node5 = new TreeNode("E");
		TreeNode node6 = new TreeNode("F");
		TreeNode node7 = new TreeNode("G");
		
		node2.add(node4); // D -> B 
		node2.add(node5); // E -> B
		node3.add(node6); // F -> C
		node3.add(node7); // G -> C
		tree.node.add(node2); // B -> A
		tree.node.add(node3); // C -> A
		
		Enumeration<TreeNode> children = tree.node.getChildren();
		while(children.hasMoreElements()){
			System.out.println(children.nextElement().getName());
		}
		
	}
	
}
